package com.controller.admin.user;

import com.dao.EditDao;
import com.dao.imp.EditDaoimpl;
import com.entity.Company;
import com.entity.User;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/EditUser")
public class EditUser extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

        doPost(req, resp);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("utf-8");
        resp.setCharacterEncoding("utf-8");
        resp.setContentType("text/html;charset=utf-8");
        String userId = req.getParameter("userId");
        String name = req.getParameter("name");
        String age = req.getParameter("age");
        String school= req.getParameter("school");
        String xueLi = req.getParameter("xueLi");
        String major = req.getParameter("major");
        String tel = req.getParameter("tel");
        String state = req.getParameter("state");
        System.out.println("state = " + state);

        User user = new User();
        user.setUserId(userId);
        user.setName(name);
        user.setAge(age);
        user.setSchool(school);
        user.setXueLi(xueLi);
        user.setMajor(major);
        user.setTel(tel);
        user.setState(state);
        System.out.println("user = " + user);


        EditDao editDao  = new EditDaoimpl();
//        int i1 =editDao.EditCompany(company);
        int i =editDao.EditUser(user);
        if(i==1){
            resp.getWriter().write("success");
        }else{
            resp.getWriter().write("fail");
        }

    }
}
